package com.pym.common;


import com.pym.enums.ResultEnum;

/**
 * @Author Jerry
 * @Description //TODO
 * @Date 9:20 2021/8/16
 **/
public class ResultMsg<T> {
    private String code;

    private String message;

    private T data;


    /**
     * 默认操作成功
     */
    public ResultMsg() {
        code = ResultCode.SUCC;
        message = ResultCode.SUCC_DESC;
    }

    /**
     * 操作成功，自定义成功提示信息
     * @param message 提示信息
     */
    public ResultMsg(String message) {
        this.code = ResultCode.SUCC;
        this.message = message;
    }

    /**
     * 默认操作失败
     * @param code 错误编号
     * @param message 提示信息
     */
    public ResultMsg(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultMsg(ResultEnum resultEnum) {
        this.code = resultEnum.getCode()+"";
        this.message = resultEnum.getMsg();
    }

    /**
     * 操作成功带数据返回
     * @param data 返回数据
     */
    public ResultMsg(T data) {
        this();
        this.data = data;
    }

    /**
     * 操作失败带数据返回
     * @param data 返回数据
     */
    public ResultMsg(String code,T data) {
        this(code,"操作失败");
        this.data = data;
    }

    /**
     * 通用数据返回消息
     * @param code 编号
     * @param message 提示消息
     * @param data 返回数据
     */
    public ResultMsg(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}